using UnityEngine;

namespace CinemaDirector
{
	[CutsceneItem("GG-Action", "Fade")]
	public class FadeAction : CinemaActorAction
	{
		public GGVFloat start;

		public GGVFloat end;

		public bool useEase;

		public AnimationCurve easeCurve;

		protected UIWidget widget;

		public override void Initialize()
		{
			base.Initialize();
			start.Init(base.Cutscene.variables);
			end.Init(base.Cutscene.variables);
		}

		public override void Trigger(GameObject actor)
		{
			if (!(actor == null))
			{
				widget = actor.GetComponent<UIWidget>();
				if (!(widget == null))
				{
					start.SetCurrent(widget.alpha);
					end.SetCurrent(widget.alpha);
					SetTime(0f);
				}
			}
		}

		public override void End(GameObject actor)
		{
			if (!(actor == null))
			{
				widget = actor.GetComponent<UIWidget>();
				if (!(widget == null))
				{
					start.SetCurrent(widget.alpha);
					end.SetCurrent(widget.alpha);
					SetTime(1f);
				}
			}
		}

		public override void UpdateTime(GameObject Actor, float time, float deltaTime)
		{
			if (!(duration <= 0f) && !(widget == null))
			{
				float time2 = time / duration;
				SetTime(time2);
			}
		}

		private void SetTime(float normTime)
		{
			if (useEase)
			{
				normTime = easeCurve.Evaluate(normTime);
			}
			widget.alpha = Mathf.Lerp(start.value, end.value, normTime);
		}
	}
}
